﻿using System;
using System.Collections.Generic;
using System.Text;
using DepInnerTask.Common.Interface;
using DepInnerTask.Common.Entity;
using IBatisNet.DataMapper;
using Common.Service;
using System.Collections;
using Common.Logging;
using DepInner;

namespace DepInnerTask.Logic
{
    class DepInnerTaskReplyLogic:IDepInnerTaskReply
    {
        public IList GetList(string where, int start, int limit, out int count)
        {
            Hashtable table = new Hashtable();
            IList list = DataHelper.Instance().GetList("DepInnerTaskReply_GetList", table, start, limit);
            count = list.Count;

            return list;
        }
        public IList GetList()
        {
            Hashtable table = new Hashtable();
            //table.Add("UPLOAD_BY", where);
            IList list = DataHelper.Instance().GetList("DepInnerTaskReply_GetList", table);
            return list;
        }
        public IList GetList1()
        {
            Hashtable table = new Hashtable();
            //table.Add("UPLOAD_BY", where);
            IList list = DataHelper.Instance().GetList("TaskRep_GetListByID", table);
            return list;
        }
        public IList GetList(string where)
        {
            Hashtable table = new Hashtable();
            table.Add("REPLY_ID", where);
            IList list = DataHelper.Instance().GetList("TaskRep_GetListByID", table);
            return list;
        }
        public DepInnerTaskReplyEntity GetByID(string taskId)
        {
            return DataHelper.Instance().Get<DepInnerTaskReplyEntity>("TaskRep_GetListByID",taskId);
        }
        public DepInnerTaskReplyEntity Get(string taskId)
        {
            return DataHelper.Instance().Get<DepInnerTaskReplyEntity>("TaskLogic_Get", taskId);
        }
        /// <summary>
        /// 根据ID查询回复信息-
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        public DepInnerTaskReplyEntity GetListByID(string taskId)
        {
            return DataHelper.Instance().Get<DepInnerTaskReplyEntity>("DepInnerTaskReply_GetListByID", taskId);
        }
        public void Insert(DepInnerTaskReplyEntity entity)
        {
            DataHelper.Instance().Insert("InsertTaskReply", entity);
        }
        /// <summary>
        /// 事务操作  添加回复信息  同时删除该代办信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="taskentity"></param>
        public void Insert(DepInnerTaskReplyEntity entity, TasksEntity taskentity)
        {
            ISqlMapSession se = DataHelper.Instance().BeginTransaction("", "");
            TasksLogic tasklogic = new TasksLogic();
            try
            {
                DataHelper.Instance().Insert("InsertTaskReply", entity);
                //先判断是否存在
                //TasksEntity ta = tasklogic.Get(taskentity.TASKID);
                //if (ta != null)
                //{
                //    DataHelper.Instance().Delete("DeleteTasksByID", taskentity);
                //}
                se.CommitTransaction();
            }
            catch (Exception)
            {
                se.RollBackTransaction();
                throw;
            }
        }
        public void Update(DepInnerTaskReplyEntity entity)
        {
            DataHelper.Instance().Update("UpdateDepInnerTaskRepByID", entity);
        }
        public void UpdateByID(DepInnerTaskReplyEntity entity)
        {
            DataHelper.Instance().Update("UpdateDepInnerTaskRepByID1", entity);
        }
        public bool Exists(string taskId)
        {
            throw new NotImplementedException();
        }

        public void Delete(string taskId)
        {
            DataHelper.Instance().Delete("DeleteTasksByID", taskId);
        }
    }
}
